﻿Imports System.Data.OleDb

Public Class PhieuDatDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from PHIEUDAT"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As PhieuDatDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into PHIEUDAT (TenKhach, DienThoai, SoNguoi, ThoiGian) values (@TenKhach, @DienThoai, @SoNguoi, @ThoiGian)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@TenKhach", tmp.TenKhach)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@SoNguoi", tmp.SoNguoi)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@ThoiGian", tmp.ThoiGian)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As PhieuDatDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update BANGCAP set TenKhach=@TenKhach, DienThoai=@DienThoai, SoNguoi=@SoNguoi, ThoiGian=@ThoiGian where MaPD=@MaPD"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5 As OleDbParameter
        para1 = New OleDbParameter("@TenKhach", tmp.TenKhach)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@SoNguoi", tmp.SoNguoi)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@ThoiGian", tmp.ThoiGian)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@MaPD", tmp.MaPD)
        cmd.Parameters.Add(para5)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As PhieuDatDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from PHIEUDAT where MaPD=@MaPD"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaPD", tmp.MaPD)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
